<?php

	// TITLE: Account_status AUTO MODEL
	// FILE: scaffolding/model/account_status.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createAccountStatus = function($con, $accountStatus) {
		$sql = 'INSERT INTO account_status (account_id, status_id, admin_who_entered, admint_when_entered) VALUES (';
		$sql .= $account_status->getAccountId() . ', ';
		$sql .= $account_status->getStatusId() . ', ';
		$sql .= $account_status->getAdminWhoEntered() . ', ';
		$sql .= $account_status->getAdmintWhenEntered() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readAccountStatus = function($con, $id) {
		$sql = 'SELECT * FROM account_status WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$accountStatus = new AccountStatus();
			$accountStatus->setAccountId($dbio->select($readAccount(result[0])));
			$accountStatus->setStatusId($dbio->select($readStatus(result[1])));
			$accountStatus->setAdminWhoEntered(result[2]);
			$accountStatus->setAdmintWhenEntered(result[3]);
		} else {
			$accountStatus = false;
		}
		return $accountStatus;
	};

	$updateAccountStatus = function($con, $accountStatus) {
		$sql = 'UPDATE account_status SET ';
		$sql .= 'account_id = ' . $account_status->getAccountId() . ', ';
		$sql .= 'status_id = ' . $account_status->getStatusId() . ', ';
		$sql .= 'admin_who_entered = ' . $account_status->getAdminWhoEntered() . ', ';
		$sql .= 'admint_when_entered = ' . $account_status->getAdmintWhenEntered() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteAccountStatus = function($con, $id) {
		$sql = 'DELETE FROM account_status WHERE account_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listAccountStatus = function($con) {
		$sql = 'SELECT * FROM account_status';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$accountStatuss = array();
			while ($result = mysqli_fetch_array($results)) {
				$accountStatus = new AccountStatus();
				$accountStatus->setAccountId($dbio->select($readAccount(result[0])));
				$accountStatus->setStatusId($dbio->select($readStatus(result[1])));
				$accountStatus->setAdminWhoEntered(result[2]);
				$accountStatus->setAdmintWhenEntered(result[3]);
				$accountStatuss[] = accountStatus;
			}// end while
		} else {
			$accountStatuss = false;
		}
		return $accountStatuss;
	};

